/**
 * 作者: wgx
 * 日期: 2024-11-13 16:38:02
 * 备注: 单服派对表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.CsGameFeast.PBServerFeast;
import com.motu.monstercity.server.game.base.CommonUtils;
import com.motu.monstercity.server.game.commondata.bag.ItemId;
import com.motu.monstercity.server.game.commondata.feast.FeastConstant;
import com.motu.monstercity.server.game.commondata.feast.FeastCreaterReward;
import com.motu.monstercity.server.game.commondata.feast.FeastJoin;
import com.motu.monstercity.server.game.commondata.feast.FeastMain;
import com.motu.monstercity.server.game.logic.FeastManager;
import com.motu.monstercity.server.game.logic.GameUser;
import com.motu.monstercity.server.game.logic.RewardItem;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.List;

public class ServerFeast extends ServerFeastModel {
    public ServerFeast() {
        super();
    }

    public ServerFeast(int serverId, UserInfo userInfo, int feastMainId, boolean isThree, JsonArray joinTypeAllow, long createTime) {
        super();
        putServerId(serverId);
        putUniqKey(FeastManager.getFeastUniqKey(userInfo.getId(), feastMainId));
        putUserId(userInfo.getId());
        putFeastMainId(feastMainId);
        putUserName(userInfo.getUserName());
        putVip(userInfo.getVip());
        putLevel(userInfo.getLevel());
        putIcon(userInfo.getIcon());
        putAddTime(createTime);
        putJoinTime(createTime);
        putIsThree(isThree ? 1 : 0);
        putJoinTypeAllow(joinTypeAllow.toString());
    }

    // 计算这个盛典派对的总人气值
    public int countCelebScore() {
        FeastCreaterReward feastCreaterReward = FeastManager.getFeastCreaterReward(getGuestNum());
        if (feastCreaterReward == null) {
            return 0;
        }
        int score = 0;
        try {
            List<RewardItem> rewardItemList = CommonUtils.takeReawrdItemFromStr(feastCreaterReward.getReward());
            for (RewardItem rewardItem : rewardItemList) {
                if (rewardItem.getItemId() == ItemId.FEAST_SCORE) {
                    return (int) rewardItem.getItemNum();
                }
            }
        } catch (Exception e) {
        }
        return score;
    }

    // 是否普通派对
    public boolean isCommonFeast() {
        FeastMain feastMain = FeastManager.getFeastMain(getFeastMainId());
        if (feastMain.isCommonFeast()) {
            return true;
        } else {
            return false;
        }
    }

    public PBServerFeast.Builder takeInitBuilder() {
        PBServerFeast.Builder sb = super.takeInitBuilder();
        UserShow userShow = GameUser.getUserShow(getUserId());
        if (userShow != null) {
            sb.setUserShow(userShow.takeInitBuilder());
        }
        return sb;
    }
}
